#ifndef CSGPRIMITIVENODEDATA_H
#define CSGPRIMITIVENODEDATA_H

#include "csgnode.h"
#include "tree/tree.h"

class CSGPrimitiveNode : public CSGNode
{
public:
    CSGPrimitiveNode();
    CSGPrimitiveNode(Expression& e, CSGNode *parent = NULL);
    ~CSGPrimitiveNode();

    // get & set
    Expression * getExpression(){return &expr;}
    void setExpression(Expression &e);

    virtual double eval(double x, double y, double z);

    // test
    virtual bool emptyTest(StarTestBox *box);
    virtual bool starTest(StarTestBox *box, double *pt);
    virtual bool complementStarTest(StarTestBox *box, double *pt);
    virtual bool ptInSet(double *pt);

    // compute
    virtual void setRotation(double _rot);
    virtual void setTranslation(double x, double y = 0);
    virtual void setScale(double x, double y = 1);

private:
    int boxContainsZero(Box *box, Expression& expr);
    int boxContainsZeroBernstein3(Box *box, Expression& expr);
    int boxContainsZeroBernstein(Box *box, Expression& expr);
    int boxContainsZeroHorner(Box *box, Expression& expr);
    bool starCondition(StarTestBox *box, Expression& starExpr, int& depth);
    void getCoeff(Expression& expr, int M, int N, double **c);
    void getCoeff3(Expression& expr, int L, int M, int N, double *c);
    Interval evalHorner(double **c, int M, int N, Box *box);
    Interval evalHorner(double **c, int M, Interval x);

    Expression computeDFDh(Expression expr);

public:
    static Variable x;
    static Variable y;
    static Variable z;
    static Expression expr_x;
    static Expression expr_y;
    static Expression expr_z;

private:
    std::vector<Expression> polyFamily;
    Expression expr;
    Expression orgExpr;
};

#endif // CSGPRIMITIVENODEDATA_H
